<?php
/**
 * Created by PhpStorm.
 * User: 戎大富
 * Date: 2020/9/15
 * Time: 9:34
 */
namespace app\admin\controller;
use think\Db;
use think\Request;
class Invoice extends Base {
    /**
     * 列表展示
     * @return mixed|\think\response\Json
     */
    public function index(){
        if(request()->isAjax()){
            $map = array();
            extract(input());
            if(isset($keyword)&&$keyword!="")
            {
                $map['a.invoice_company|a.invoice_phone'] = ['like',"%" . $keyword . "%"];
            }
            $map['a.invoice_status'] = 2;
            $NowPage = input('page') ? input('page') : 1;
            $limits = input("limit") ? input("limit") : 10;
            $count = Db::name('invoice')->alias('a')
                ->join('up_u_user uuu','uuu.user_id = a.user_id','left')
                ->join('up_u_user uuu1','uuu1.user_id = a.qy_user_id','left')
                ->where($map)->count();// 获取总条数
            $lists = Db::name('invoice')->alias('a')
                ->join('up_u_user uuu','uuu.user_id = a.user_id','left')
                ->join('up_u_user uuu1','uuu1.user_id = a.qy_user_id','left')
                ->where($map)
                ->page($NowPage,$limits)
                ->field('a.*,uuu.user_username,uuu1.user_username as username')
                ->order('invoice_id desc')
                ->select();
            return json(['code' => 220, 'msg' => '', 'count' => $count, 'data' => $lists]);
        }
        return $this->fetch();
    }
    public function up(){
        $task_id = input('param.id');
        $res = Db::name('invoice')->where('invoice_id',$task_id)->setField('invoice_status',3);
        if($res){
            return json(['code'=>200,'msg'=>'操作成功']);
        }else{
            return json(['code'=>100,'msg'=>'操作失败']);
        }
    }
}